import { Parameter } from '$common';
import { ValidationError } from 'joi';
import { OutputParameter } from '$domain/model/driver';

export type BaseResponese = {
  success: boolean,
  data?: any,
  message?: string
}
export interface JobContext {
  userId: string;
  appId: string;
  nodeId: string;
  jobId: string;
  debug?: boolean;
}

export enum ParameterType {
  NUMBER = 'number',
  STRING = 'string',
  ARRAY = 'array',
  FILE = 'file',
  CSV = 'csv',
  XLSX = 'xlsx',
  ZIP = 'zip'
}

export interface SimulationParameter extends Parameter {
  type: ParameterType,
  unit?: string,
  guiPath?: string,
}

export enum JobStatus {
  Created = 'Created',
  Queuing = 'Queuing',
  Prepareing = 'Prepareing',
  Runing = 'Running',
  Finished = 'Finished',
  Interrupted = 'Interrupted'
}

export type ModelLocationType = 'local' | 'remote';

export type SimulationModel = {
  type: ModelLocationType,
  file: string,
  entry?: string
};

export interface EnvironmentVariable {
  name: string,
  value: string
}

export interface SimulationSpec {
  runMode: 'native' | 'hpcc',
  model: SimulationModel,
  parameters?: SimulationParameter[],
  environments: EnvironmentVariable[],
  config?: {
    timeout: number,
  },
  result: {
    specifiedLocalPath?: string,
    uploadRawSimResult?: boolean,
    specifiedOutputParams?: unknown[],
  },
  extendedProperties?: {
    [extendedProperties: string]: unknown
  }
}

export interface SimulationRequest {
  id: string
  product: string,
  context: JobContext;
  definition: SimulationSpec;
}

export type ValidateResult = { error: ValidationError, value: SimulationRequest};

export enum SimJobStatus {
  Created = 'created',
  AgentAssigned = 'agentAssigned',
  AgentDispatched = 'agentDispatched',
  Running = 'running',
  Succeed = 'succeed',
  Failed = 'failed',
  Interrupt = 'interrupt',
  UnKnown = 'unknown'
}

export type JobResultData = {
  simulationResultZip?: string,
  specifiedParameters?: OutputParameter[]
}
export interface JobResultNotification {
  id: string,
  success: boolean,
  message: string,
  result?: JobResultData
}
export interface ModelParseParamRequest {
  product: string,
  type: 'local' | 'remote',
  modelPath: string,
  entry?: string
}

export interface SimProcess {
  progress: number
}

export interface StopJobRequest {
  jobId: string,
  modelBack: boolean
}